//  配置插件vuex-persistedstate插件
import createPersistedState from 'vuex-persistedstate'
import { RootState } from '@/store/types'
import SecureLS from 'secure-ls'
const ls = new SecureLS({
  encodingType: 'default',
  isCompression: true,
  encryptionSecret: 'maxotm'
})

// import * as Cookies from 'js-cookie'
// storage: {
//         getItem: key => Cookies.get(key),
//         setItem: (key, value) => Cookies.set(key, value, { expires: 7 }),
//         removeItem: key => Cookies.remove(key)
//       }
export default createPersistedState({
  key: 'Persisted', // 定义KEY名
  storage: window.localStorage, // 定义信息存储模式：window.localStorage（默认）、sessionStorage、cookie
  // storage: {
  //   getItem: key => ls.get(key),
  //   setItem: (key, value) => ls.set(key, value),
  //   removeItem: key => ls.remove(key)
  // },
  reducer(state: RootState) {
    return {
      menu: {
        articles: state.menu.articles,
        items: state.menu.items
      },
      user: {
        roles: state.user.roles,
        userInfo: state.user.userInfo
      },
      setting: {
        color: state.setting.color,
        miniVariant: state.setting.miniVariant,
        search: state.setting.search
      },
      loginStatus: state.user.token
    }
  }
})
